﻿use SSODemo;

--region Drop Existing Procedures

IF OBJECT_ID(N'[usp_InsertAccountAppUser]') IS NOT NULL
	DROP PROCEDURE [usp_InsertAccountAppUser]

IF OBJECT_ID(N'[usp_UpdateAccountAppUser]') IS NOT NULL
	DROP PROCEDURE [usp_UpdateAccountAppUser]

IF OBJECT_ID(N'[usp_DeleteAccountAppUser]') IS NOT NULL
	DROP PROCEDURE [usp_DeleteAccountAppUser]

IF OBJECT_ID(N'[usp_DeleteAccountAppUsersDynamic]') IS NOT NULL
	DROP PROCEDURE [usp_DeleteAccountAppUsersDynamic]

IF OBJECT_ID(N'[usp_SelectAccountAppUser]') IS NOT NULL
	DROP PROCEDURE [usp_SelectAccountAppUser]

IF OBJECT_ID(N'[usp_SelectAccountAppUsersDynamic]') IS NOT NULL
	DROP PROCEDURE [usp_SelectAccountAppUsersDynamic]
	
IF OBJECT_ID(N'[usp_DeleteAccountAppUsersByAccountAppID]') IS NOT NULL
	DROP PROCEDURE [usp_DeleteAccountAppUsersByAccountAppID]
	
--endregion

GO

--region [usp_InsertAccountAppUser]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_InsertAccountAppUser]
-- Date Generated: 2009-04-28
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_InsertAccountAppUser]
	@Name varchar(20),
	@Password varchar(50),
	@DateCreated datetime,
	@AccountAppID uniqueidentifier,
	@ID uniqueidentifier
AS

SET NOCOUNT ON

INSERT INTO [AccountAppUser] (
	[ID],
	[Name],
	[Password],
	[DateCreated],
	[AccountAppID]
) VALUES (
	@ID,
	@Name,
	@Password,
	@DateCreated,
	@AccountAppID
)

--endregion

GO

--region [usp_UpdateAccountAppUser]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_UpdateAccountAppUser]
-- Date Generated: 2009-04-28
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_UpdateAccountAppUser]
	@ID uniqueidentifier,
	@Name varchar(20),
	@Password varchar(50),
	@DateCreated datetime,
	@AccountAppID uniqueidentifier
AS

SET NOCOUNT ON

UPDATE [AccountAppUser] SET
	[Name] = @Name,
	[Password] = @Password,
	[DateCreated] = @DateCreated,
	[AccountAppID] = @AccountAppID
WHERE
	[ID] = @ID

--endregion

GO

--region [usp_DeleteAccountAppUser]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_DeleteAccountAppUser]
-- Date Generated: 2009-04-28
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_DeleteAccountAppUser]
	@ID uniqueidentifier
AS

SET NOCOUNT ON

DELETE FROM [AccountAppUser]
WHERE
	[ID] = @ID

--endregion

GO

--region [usp_DeleteAccountAppUsersDynamic]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_DeleteAccountAppUsersDynamic]
-- Date Generated: 2009-04-28
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_DeleteAccountAppUsersDynamic]
	@WhereCondition nvarchar(500)
AS

SET NOCOUNT ON

DECLARE @SQL nvarchar(3250)

SET @SQL = '
DELETE FROM
	[AccountAppUser]
WHERE
	' + @WhereCondition

EXEC sp_executesql @SQL

--endregion

GO

--region [usp_SelectAccountAppUser]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_SelectAccountAppUser]
-- Date Generated: 2009-04-28
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_SelectAccountAppUser]
	@ID uniqueidentifier
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[ID],
	[Name],
	[Password],
	[DateCreated],
	[AccountAppID]
FROM
	[AccountAppUser]
WHERE
	[ID] = @ID

--endregion

GO

--region [usp_SelectAccountAppUsersDynamic]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_SelectAccountAppUsersDynamic]
-- Date Generated: 2009-04-28
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_SelectAccountAppUsersDynamic]
	@WhereCondition nvarchar(500),
	@OrderByExpression nvarchar(250) = NULL
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

DECLARE @SQL nvarchar(3250)

SET @SQL = '
SELECT
	[ID],
	[Name],
	[Password],
	[DateCreated],
	[AccountAppID]
FROM
	[AccountAppUser]
WHERE
	' + @WhereCondition

IF @OrderByExpression IS NOT NULL AND LEN(@OrderByExpression) > 0
BEGIN
	SET @SQL = @SQL + '
ORDER BY
	' + @OrderByExpression
END

EXEC sp_executesql @SQL

--endregion

GO

--region [usp_DeleteAccountAppUsersByAccountAppID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   Zyg
-- Procedure Name: [usp_DeleteAccountAppUsersByAccountAppID]
-- Date Generated: 2009-04-29
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [usp_DeleteAccountAppUsersByAccountAppID]
	@AccountAppID uniqueidentifier
AS

SET NOCOUNT ON

DELETE FROM [AccountAppUser]
WHERE
	[AccountAppID] = @AccountAppID

GO

--endregion

GO